package com.itheima.web;

import com.itheima.service.BrandService;
import com.itheima.service.BrandServiceimp.brandServiceimp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

//@WebServlet("/deletById")
public class deletById extends HttpServlet {
    private BrandService brandService = new brandServiceimp();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 从请求参数中获取id
        String paramId = request.getParameter("id");

        // 确保参数存在并且是有效的数字
        if (paramId != null && !paramId.isEmpty()) {
            try {
                int brandId = Integer.parseInt(paramId);
                // 调用删除服务
                brandService.delete(brandId);
                response.getWriter().write("success");
            } catch (NumberFormatException e) {
                response.getWriter().write("error: Invalid id");
            }
        } else {
            response.getWriter().write("error: No id provided");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
